<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="/js/plugins/layer/laydate/skins/default/laydate.css" />
<style>
	#btnGetsbm{
		position: absolute;
		top: 2px;
		right: 17px;
	}
</style>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title" style="padding-bottom: 0;">
						<div class="">
							<ul class="nav nav-tabs">
								<li class="active"><a href="#basic_info" data-toggle="tab">基本信息</a></li>
								<li><a href="#photo_info" data-toggle="tab">附加信息</a></li>
							</ul>
						</div>
					</div>
					<input id="pageType" th:value="${pageType}"  type="hidden">
					<form class="form-horizontal" id="signupForm">
						<input id="id" name="id" th:value="${unitBasicinfo.id}"  type="hidden">
						<div class="tab-content">
							<!--basic info-->
							<div class="ibox-content tab-pane fade in active"  id="basic_info">
								<div class="form-group">
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>名称：</label>
									<div class="col-sm-3">
										<input id="xxmc" name="xxmc" th:value="${unitBasicinfo.xxmc}" class="form-control" type="text" maxlength="50">
									</div>
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>拼音简称：</label>
									<div class="col-sm-3">
										<input id="xxpyjc" name="xxpyjc" th:value="${unitBasicinfo.xxpyjc}" class="form-control" type="text" maxlength="64">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">学校简称：</label>
									<div class="col-sm-3">
										<input id="xxjc" name="xxjc" th:value="${unitBasicinfo.xxjc}" class="form-control" type="text" maxlength="50">
									</div>
									<label class="col-sm-3 control-label">英文名称：</label>
									<div class="col-sm-3">
										<input id="xxywmc" name="xxywmc" th:value="${unitBasicinfo.xxywmc}" class="form-control" type="text" maxlength="120">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>所属区县：</label>
									<div class="col-sm-3">
										<select  class="form-control select2" id="ssqx" name="ssqx">
											<option  th:selected="${unitBasicinfo.ssqx eq c.key}" th:each="c:${ssqxMap}"  th:value="${c.key}" th:text="${c.value}" ></option>
										</select>
									</div>
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>学校(机构)识别码：</label>
									<div class="col-sm-3">
										<input id="xxsbm" name="xxsbm" th:value="${unitBasicinfo.xxsbm}" class="form-control" type="text">

										<button type="button" class="btn btn-primary btn-sm hidden" id="btnGetsbm" onclick="getBsmAuto();"  title="刷新标识码"><i class="fa fa-refresh"></i></button>
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>类型：</label>
									<div class="col-sm-3">
										<select  class="form-control select2" id="xxlx" name="xxlx">
											<option  th:selected="${unitBasicinfo.xxlx eq c.key}" th:each="c:${application.jyrc_xxlx_}"  th:value="${c.key}" th:text="${c.value}" ></option>
										</select>
									</div>
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>类别：</label>
									<div class="col-sm-3">
										<select  class="form-control select2" id="xxlb" name="xxlb">
											<option  th:selected="${unitBasicinfo.xxlb eq c.key}" th:each="c:${application.jyrc_xxlb_}"  th:value="${c.key}" th:text="${c.value}" ></option>
										</select>
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>状态：</label>
									<div class="col-sm-3">
										<select  class="form-control select2" id="flag" name="flag">
											<option  th:selected="${unitBasicinfo.flag eq c.key}" th:each="c:${application.jyrc_xxflag_}"  th:value="${c.key}" th:text="${c.value}" ></option>
										</select>
									</div>
									<label class="col-sm-3 control-label">学校(机构)代码：</label>
									<div class="col-sm-3">
										<input id="xxdm" name="xxdm" th:value="${unitBasicinfo.xxdm}" class="form-control" type="text" maxlength="32">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label">成立年月：</label>
									<div class="col-sm-3">
										<input class="laydate-icon layer-date form-control" type="text" id="jxny"  name="jxny" th:value="${unitBasicinfo.jxny}" onclick="WdatePicker({dateFmt:'yyyy-MM'})" maxlength="10" readonly/>
									</div>
									<label class="col-sm-3 control-label">学校邮编：</label>
									<div class="col-sm-3">
										<input id="xxyb" name="xxyb" th:value="${unitBasicinfo.xxyb}" class="form-control" type="text" maxlength="10">
									</div>

								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">联系电话：</label>
									<div class="col-sm-3">
										<input id="lxdh" name="lxdh" th:value="${unitBasicinfo.lxdh}" class="form-control" type="text" maxlength="18">
									</div>
									<label class="col-sm-3 control-label">电子信箱：</label>
									<div class="col-sm-3">
										<input id="dzxx" name="dzxx" th:value="${unitBasicinfo.dzxx}" class="form-control" type="text" maxlength="64">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label">地址：</label>
									<div class="col-sm-3">
										<input id="xxdz" name="xxdz" th:value="${unitBasicinfo.xxdz}" class="form-control" type="text">
									</div>
									<label class="col-sm-3 control-label">备注：</label>
									<div class="col-sm-3">
										<input id="bz" name="bz" th:value="${unitBasicinfo.bz}" class="form-control" type="text">
									</div>
								</div>


							</div>
							<div class="ibox-content tab-pane fade" id="photo_info">
								<div class="form-group">
									<label class="col-sm-3 control-label">传真电话：</label>
									<div class="col-sm-3">
										<input id="czdh" name="czdh" th:value="${unitBasicinfo.czdh}" class="form-control" type="text" maxlength="18">
									</div>
									<label class="col-sm-3 control-label">网站主页地址：</label>
									<div class="col-sm-3">
										<input id="wzzydz" name="wzzydz" th:value="${unitBasicinfo.wzzydz}" class="form-control" type="text" maxlength="64">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">校长姓名：</label>
									<div class="col-sm-3">
										<input id="xzxm" name="xzxm" th:value="${unitBasicinfo.xzxm}" class="form-control" type="text" maxlength="32">
									</div>
									<label class="col-sm-3 control-label">校长手机号码：</label>
									<div class="col-sm-3">
										<input id="xzsjh" name="xzsjh" th:value="${unitBasicinfo.xzsjh}" class="form-control" type="text" maxlength="18">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label">学校所属主管教育行政部门代码：</label>
									<div class="col-sm-3">
										<input id="xxsszgjyxzbmdm" name="xxsszgjyxzbmdm" th:value="${unitBasicinfo.xxsszgjyxzbmdm}" class="form-control" type="text" maxlength="32">
									</div>
									<label class="col-sm-3 control-label">学校办学类型码：</label>
									<div class="col-sm-3">
										<input id="xxbxlxm" name="xxbxlxm" th:value="${unitBasicinfo.xxbxlxm}" class="form-control" type="text" maxlength="32">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">学校（机构）性质类别码：</label>
									<div class="col-sm-3">
										<input id="xxjgxzkbm" name="xxjgxzkbm" th:value="${unitBasicinfo.xxjgxzkbm}" class="form-control" type="text" maxlength="32">
									</div>
									<label class="col-sm-3 control-label">学校举办者码：</label>
									<div class="col-sm-3">
										<input id="xxjbzm" name="xxjbzm" th:value="${unitBasicinfo.xxjbzm}" class="form-control" type="text" maxlength="32">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">是否寄宿学校：</label>
									<div class="col-sm-3">
										<div class="radio i-checks">
											<label class="radio-inline" th:each="c:${application.yes_no_}">
												<input th:field="*{unitBasicinfo.sfjsxx}" type="radio" name="sfjsxx" th:value="${c.key}" th:text="${c.value}"/>
											</label>
										</div>
									</div>
									<label class="col-sm-3 control-label">是否边境学校：</label>
									<div class="col-sm-3">
										<div class="radio i-checks">
											<label class="radio-inline" th:each="c:${application.yes_no_}">
												<input th:field="*{unitBasicinfo.sfbjxx}" type="radio" name="sfbjxx" th:value="${c.key}" th:text="${c.value}"/>
											</label>
										</div>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">是否随班就读：</label>
									<div class="col-sm-3">
										<div class="radio i-checks">
											<label class="radio-inline" th:each="c:${application.yes_no_}">
												<input th:field="*{unitBasicinfo.sfsbjd}" type="radio" name="sfsbjd" th:value="${c.key}" th:text="${c.value}"/>
											</label>
										</div>
									</div>
									<label class="col-sm-3 control-label">是否分校区：</label>
									<div class="col-sm-3">
										<div class="radio i-checks">
											<label class="radio-inline" th:each="c:${application.yes_no_}">
												<input th:field="*{unitBasicinfo.sffxq}" type="radio" name="sffxq" th:value="${c.key}" th:text="${c.value}"/>
											</label>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="ibox-content">
							<div class="form-group"  style="margin:0 auto;width:200px;">
								<div class="col-sm-8 col-sm-offset-5">
									<button id ="btnSave" type="button" class="btn btn-primary">提交</button>
								</div>
							</div>
						</div>
					</form>

				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/jquery.datepick.js"></script>
	<script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
        $().ready(function() {
            var pageType = $('#pageType').val();
            if('save'==pageType){//新增页面
                $('#xxsbm').attr('title','请仔细确认当前学校标识码再进行新增,若没有标识码可进行手动生成,新增后不可修改请认真填写。');
                $('#btnGetsbm').attr('title','请仔细确认当前学校标识码再进行新增,若没有标识码可进行手动生成,新增后不可修改请认真填写。');
                $('#btnGetsbm').removeClass("hidden");
                $('#xxmc').on('blur',function(){
                    if($(this).val()!='')getXxmcAuto();
                });
                $('#xxpyjc').focus(function(){
                    if($(this).val()==''){
                        if($('#xxmc').val()!='')
                            getXxmcAuto();
                    }
                });
                $('#xxpyjc').on('blur',function(){
                    if($(this).val()!='')$(this).val($(this).val().toUpperCase());
                });
            }else if('update'==pageType){//修改页面
                $('#xxsbm').attr({"disabled":"disabled"});
                $('#xxmc').on('blur',function(){
                    if($(this).val()!='')getXxmcAuto();
                });
                $('#xxpyjc').on('blur',function(){
                    if($(this).val()!='')$(this).val($(this).val().toUpperCase());
                });
                $('#xxpyjc').focus(function(){
                    if($(this).val()==''){
                        if($('#xxmc').val()!='')
                            getXxmcAuto();
                    }
                });
            }else if ('look' == pageType) {//查看页面

                Util.disableInput();//页面不可修改

            }else{
                parent.layer.msg("页面参数错误");
            }

            $('#btnSave').click(function(){
                if(beforeSave()){
                    $('#btnSave').attr({"disabled":"disabled"});
                    $.post("/sys/unitBasicinfo/"+$('#pageType').val(), $('#signupForm').serialize(), function(data){
                        if (data.code == 0) {
                            parent.layer.msg("操作成功");
                            $(window.parent.document).find('.J_iframe').each(function () {
                                if ($(this).data('id') == "/sys/unitBasicinfo") {///sys/unitBasicinfo为打开的frame id
                                    this.contentWindow.reLoad();
                                    return false;
                                }
                            });
                            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                            parent.layer.close(index);

                        } else {
                            $("#btnSave").removeAttr("disabled");
                            parent.layer.alert(data.msg)
                        }
                    });
                }
            });
        });


        //手动获取标识码
        function getBsmAuto(){
            $.post("/sys/unitBasicinfo/getSchoolSbmAuto", function(data){
                $('#xxsbm').val(data.schoolBsm);
            });
        }

        //根据学校名称获取拼音首字母缩写
        function getXxmcAuto(){
            var param ={};
            param.schoolName =$('#xxmc').val();
            $.getJSON("/sys/unitBasicinfo/getSchoolMzSzm",param,function(data){
                $('#xxpyjc').val(data.schoolPyMc);
            });
        }

        function beforeSave(){
            var flag = true;
            if($('#xxmc').val()==''|| $('#xxsbm').val()=='' ||$('#xxpyjc').val()==''||$('#ssqx').val()=='' ){
                flag = false;
                parent.layer.msg("带*的为必填项，请补充完整。");
            }else if($('#dzxx').val()!="" && !isEmail($('#dzxx').val())){
                flag = false;
                parent.layer.msg("电子信箱不正确");
                $('#dzxx').focus();
            }else if ( $("#xzsjh").val()!="" && !IsTel($("#xzsjh").val()) ) {
                flag = false;
                parent.layer.msg("手机号格式不正确");
                $('#xzsjh').focus();
            }
            return flag;
        }

        function isEmail(str){
            var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            return reg.test(str);
        }

        function IsTel(str){
            var reg = /^((1)+\d{10})$/;
            return reg.test(str);
        }

	</script>
</body>
</html>
